/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.token.domain.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 
 * @author Ramesh
 */
@Entity
@Table(name = "employee")
@XmlRootElement
@NamedQueries({
	@NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e"),
	@NamedQuery(name = "Employee.findById", query = "SELECT e FROM Employee e WHERE e.id = :id"),
	@NamedQuery(name = "Employee.findByEmailId", query = "SELECT e FROM Employee e WHERE e.emailId = :emailId"),
	@NamedQuery(name = "Employee.findByEmpCode", query = "SELECT e FROM Employee e WHERE e.empCode = :empCode"),
	@NamedQuery(name = "Employee.findByFirstName", query = "SELECT e FROM Employee e WHERE e.firstName = :firstName"),
	@NamedQuery(name = "Employee.findByLastName", query = "SELECT e FROM Employee e WHERE e.lastName = :lastName"),
	@NamedQuery(name = "Employee.findByMiddleInitial", query = "SELECT e FROM Employee e WHERE e.middleInitial = :middleInitial"),
	@NamedQuery(name = "Employee.findByPrefix", query = "SELECT e FROM Employee e WHERE e.prefix = :prefix"),
	@NamedQuery(name = "Employee.findByPhoneNo", query = "SELECT e FROM Employee e WHERE e.phoneNo = :phoneNo"),
	@NamedQuery(name = "Employee.findAllByCompanyId", query = "SELECT e FROM Employee e WHERE e.company.id = :companyId") })
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    private Long id;
    private String emailId;
    private String empCode;
    private String firstName;
    private String lastName;
    private String middleInitial;
    private Integer prefix;
    private String phoneNo;
    /*
     * @OneToOne(mappedBy = "employee") private Login login;
     */
    @ManyToOne
    private Company company;

    @ManyToOne
    private Destination destination;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "employee")
    private Collection<EmployeeDocument> documents = new ArrayList<EmployeeDocument>();

    public Employee() {
    }

    public Employee(Long id) {
	this.id = id;
    }

    public void addDocument(EmployeeDocument document) {
	if (documents != null) {
	    documents.add(document);
	} else {
	    documents = new ArrayList<EmployeeDocument>();
	    documents.add(document);
	}
    }

    public Long getId() {
	return id;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public String getEmailId() {
	return emailId;
    }

    public void setEmailId(String emailId) {
	this.emailId = emailId;
    }

    public String getEmpCode() {
	return empCode;
    }

    public void setEmpCode(String empCode) {
	this.empCode = empCode;
    }

    public String getFirstName() {
	return firstName;
    }

    public void setFirstName(String firstName) {
	this.firstName = firstName;
    }

    public String getLastName() {
	return lastName;
    }

    public void setLastName(String lastName) {
	this.lastName = lastName;
    }

    public String getMiddleInitial() {
	return middleInitial;
    }

    public void setMiddleInitial(String middleInitial) {
	this.middleInitial = middleInitial;
    }

    public Integer getPrefix() {
	return prefix;
    }

    public void setPrefix(Integer prefix) {
	this.prefix = prefix;
    }

    public String getPhoneNo() {
	return phoneNo;
    }

    public void setPhoneNo(String phoneNo) {
	this.phoneNo = phoneNo;
    }

    /*
     * public Login getLogin() { return login; }
     * 
     * public void setLogin(Login login) { this.login = login; }
     */
    public Company getCompany() {
	return company;
    }

    public void setCompany(Company company) {
	this.company = company;
    }

    public Destination getDestination() {
	return destination;
    }

    public void setDestination(Destination destination) {
	this.destination = destination;
    }

    @Override
    public int hashCode() {
	int hash = 0;
	hash += (id != null ? id.hashCode() : 0);
	return hash;
    }

    @Override
    public boolean equals(Object object) {
	if (!(object instanceof Employee)) {
	    return false;
	}
	Employee other = (Employee) object;
	if ((this.id == null && other.id != null)
		|| (this.id != null && !this.id.equals(other.id))) {
	    return false;
	}
	return true;
    }

    @Override
    public String toString() {
	// return "Employee{" + "id=" + id + ", emailId=" + emailId +
	// ", empCode=" + empCode + ", firstName=" + firstName + ", lastName=" +
	// lastName + ", middleInitial=" + middleInitial + ", prefix=" + prefix
	// + ", phoneNo=" + phoneNo + ", login=" + /*login*/ ", company=" +
	// company + '}';
	return "Employee{" + "id=" + id + "}";
    }

}
